# redis_config.py
import redis


class RedisClient:
    def __init__(self, host='rapid-build-redis', port=6379, db=1, decode_responses=True):
        self.client = redis.Redis(host=host, port=port, db=db, decode_responses=decode_responses)

    def get_key(self, key):
        return self.client.get(key)

    def set_key(self, key, value):
        self.client.set(key, value)

    def set_key_with_expiry(self, key, value, time):
        self.client.setex(key, time, value)

    def hget(self, name, key):
        return self.client.hget(name, key)

    def hset(self, name, key, value):
        self.client.hset(name, key, value)


# 实例化 Redis 客户端
redis_client = RedisClient()
